package com.richpencil.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class DateUtils {
	public static long getSecondsFromObjectValueToNow(Object datetimevalue) throws ParseException
	{
		if(!StringHelper.IsEmptyOrNull(datetimevalue))
		{
			String value=datetimevalue.toString();
			return getSecondsFromStringValueToNow(value);
		}
		else 
		{
			return 0;
		}
	}
	
	public static long getSecondsFromStringValueToNow(String datetimevalue) throws ParseException
	{
		Date nowTime = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date endTime = sdf.parse(datetimevalue);
		long interval = (endTime.getTime() - nowTime.getTime()) / 1000;
		return interval;
	}
	

	
	
	public static boolean CheckIsDate(String value){
		try{
			SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
			String yyyy=value.substring(0,4);
			String mm=value.substring(4,6);
			String dd=value.substring(6,8);
			String date=yyyy+"-"+mm+"-"+dd;
			sdf.parse(date);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	//获取当前日期的前N天
	public static String GetCurrentDateFrontDay(int num){
		Calendar calendar2 = Calendar.getInstance();
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
		calendar2.add(Calendar.DATE, -num);
		String three_days_after = sdf2.format(calendar2.getTime());
		return three_days_after;
	}
	//获取当前日期(yyyy-MM-dd)格式
	public static String GetCurrentDate(){
		SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String v=bartDateFormat.format(date); 
		return v;
	}
	//获取当前日期加时间(yyyy-MM-dd HH:mm:ss)格式
	public static String GetCurrentDateTime(){
		SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		String v=bartDateFormat.format(date); 
		return v;
	}
}
